/**
 *
 */
package com.hula.onion.book.server.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Component;

/**
 * Description:Spring Context Utils
 * Create Date:2018/1/17 19:37
 *
 * @author liangbing
 * @version 1.0
 */
@Component
public class ApplicationContextUtils extends ApplicationObjectSupport {

    /**
     * 根据传进来的class返回实体bean
     *
     * @param clazz
     * @return
     */
    public <T> T getBean(Class<T> clazz) {
        ApplicationContext applicationContext = getApplicationContext();
        T bean = applicationContext.getBean(clazz);
        return bean;
    }

    /**
     * 根据传进来的beanName返回实体Object
     *
     * @param beanName
     * @return
     */
    public Object getBean(String beanName) {
        ApplicationContext applicationContext = getApplicationContext();
        Object bean = applicationContext.getBean(beanName);
        return bean;
    }
}
